<template>
    <el-form :model="form"
             :rules="rules"
             ref="formRef">
        <el-form-item label="服务项标题"
                      prop="serviceName"
                      :label-width="formLabelWidth">
            <el-input v-model="form.serviceName"></el-input>
        </el-form-item>
        <el-form-item label="服务项内容"
                      prop="description"
                      :label-width="formLabelWidth">
            <el-input v-model="form.description"></el-input>
        </el-form-item>

        <el-form-item :label-width="formLabelWidth">
            <el-button plain
                       @click="resetForm('formRef')">取消</el-button>
            <el-button type="primary"
                       @click="submitForm('formRef')">确定</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
export default {
    name: "",
    props: ["data"],
    data() {
        return {
            form: {
                serviceName: "",
                description: ""
            },
            formLabelWidth: "150px",
            rules: {
                serviceName: [
                    { required: true, message: "请输入服务项标题", trigger: "blur" }
                ],
                description: [
                    { required: true, message: "请输入服务项内容", trigger: "blur" }
                ]
            }
        };
    },
    components: {},
    computed: {},
    beforeMount() { },
    mounted() {
        this.form = this.data;
    },
    methods: {
        resetForm(formName) {
           
            this.$emit("cancel", false);
        },
        submitForm(formName) {
            this.form.serviceName = this.form.serviceName.replace(/^\s+|\s+$/g, "");
            this.form.description = this.form.description.replace(/^\s+|\s+$/g, "");
            this.$refs[formName].validate(valid => {
                if (valid) {
                    this.$service
                        .updateService({
                            id: this.data.id,
                            serviceName: this.form.serviceName, //String	服务名称
                            description: this.form.description //String	服务描述
                        })
                        .then(res => {
                            if (res.code == "B0001") {
                                this.$message.error(res.message);
                            } else {
                                this.$message({
                                    message: "修改成功",
                                    type: "success"
                                });
                                this.$refs[formName].resetFields();
                                this.$emit("submit", false);
                            }
                        });
                }
            });
        }
    },
    watch: {}
};
</script>
<style scoped>
</style>
